home *** CD-ROM | disk | FTP | other *** search
/ F1 Licenseware / F1 Licenseware - Volume 1.iso / disks / 049b.dms / 049b.adf / MORE_SOURCE_CODE / Stars.AMOS / Stars.amosSourceCode
AMOS Source Code  |  1992-02-26  |  3KB  |  63 lines

  1. '            *************************************** 
  2. '            ***       Going out with Stars      *** 
  3. '            ***                                 *** 
  4. '            ***               By                *** 
  5. '            ***                                 *** 
  6. '            ***       P A U L   O V E R Y       *** 
  7. '            ***                                 *** 
  8. '            ***  This uses integer maths only.  *** 
  9. '            ***            -------              *** 
  10. '            *************************************** 
  11. '
  12. ' Note: This program can easly be turned into a fast piece of  
  13. '       machine code. As I have gone out of my way to use only 
  14. '       integers and logical shifts, which CPU's are really only good at.
  15. '  
  16. Set Buffer 64 : Hide : NUM_COLS=16
  17. Screen Open 0,320,256,NUM_COLS,Lowres : Flash Off : Curs Off : Cls 0
  18. N=64 : Rem number of stars
  19. HOW_RANDOM=128
  20. Dim SPEED(N),G(N),R(N),T(N),MX(N),MY(N)
  21. Dim X(N),Y(N),C(N),OX(N),OY(N),RAN(HOW_RANDOM),S_RAN(HOW_RANDOM),TIME(HOW_RANDOM)
  22. '
  23. ' Set grey shade colours.  
  24. For K=0 To NUM_COLS-1 : Colour K,(16/NUM_COLS*$111)*K : Next K
  25. '
  26. ' How quick should stars speed up
  27. For K=0 To N : C(K)=1 : SPEED(K)=2^Rnd(2)*NUM_COLS : Next K
  28. '
  29. LOC=0 : Rem array LOCation pointer 
  30. PRE_CALC=HOW_RANDOM-2 : Rem Offset for random number array.  
  31. '
  32. ' Speed up main routine by generating all random numbers now.
  33. For K=0 To HOW_RANDOM : Rem larger number gives more variority.
  34.    RAN(K)=Rnd(128)-64
  35.    S_RAN(K)=2^Rnd(2)*16
  36.    TIME(K)=Rnd(20)+25
  37. Next K
  38. '
  39. Do 
  40.    For K=0 To N
  41.       ' Speed up star. 
  42.       Add MX(K),MX(K)/SPEED(K) : Add MY(K),MY(K)/SPEED(K)
  43.       ' calculate new star position. 
  44.       Add X(K),MX(K)/16 : Add Y(K),MY(K)/16 : Dec C(K)
  45.       If C(K)=0
  46.          Add LOC,1,0 To PRE_CALC : Rem Array lookup point 
  47.          MX(K)=RAN(LOC)*16 : Rem    new angle 
  48.          MY(K)=RAN(LOC+2)*16 : Rem   "   "  
  49.          X(K)=5120+MX(K) : Y(K)=4096+MY(K)
  50.          Rem 160*32=5120, 128*32=4096, centre dots. 
  51.          SPEED(K)=S_RAN(LOC) : Rem  New Speed.  
  52.          C(K)=TIME(LOC) : Rem       Counter for resetting stars.   
  53.          R(K)=C(K)/NUM_COLS : Rem   Colour fade out reset value. 
  54.          T(K)=R(K) : Rem            Colour fade out counter.  
  55.          G(K)=0 : Rem               Start with a black star. 
  56.       End If 
  57.       Dec T(K) : If T(K)=-1 Then Inc G(K) : T(K)=R(K)
  58.       Plot OX(K),OY(K),0 : Rem Remove old star
  59.       ' Use large numbers & divide them down instead of using floats.
  60.       OX(K)=X(K)/32 : OY(K)=Y(K)/32
  61.       Plot OX(K),OY(K),G(K) : Rem plot new star
  62.    Next K
  63. Loop